package com.mywang.weitravel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.mywang.weitravel.R;
import com.mywang.weitravel.model.ReadDetailBean;
import com.mywang.weitravel.util.ImageLoader;

import java.util.List;

public class ReadChinaAdapter extends RecyclerView.Adapter<ReadChinaAdapter.MyHolder> {

    private List<ReadDetailBean> mList;

    private LayoutInflater layoutInflater;

    private Context context;

    public ReadChinaAdapter(Context context, List<ReadDetailBean> list) {
        super();
        this.mList = list;
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_read_detail, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        ReadDetailBean bean = mList.get(position);
        holder.tv_title.setText(bean.getTitle());
        ImageLoader.getInstance().displayImage(context, bean.getFilepath(), holder.iv_pic);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        ImageView iv_pic;
        TextView tv_title;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            iv_pic = itemView.findViewById(R.id.iv_pic);
            tv_title = itemView.findViewById(R.id.tv_title);
        }
    }

//    @Override
//    public int getCount() {
//        return mList.size();
//    }
//
//    /**
//     * 页面宽度所占ViewPager测量宽度的权重比例，默认为1
//     */
//    @Override
//    public float getPageWidth(int position) {
//        return (float) 0.8;
//    }
//
//    @Override
//    public boolean isViewFromObject(View view, Object object) {
//        return view == object;
//    }
//
//    @Override
//    public void destroyItem(ViewGroup container, int position, Object object) {
//        View view = (View) object;
//        ((ViewPager) container).removeView(view);
//    }
//
//    @Override
//    public Object instantiateItem(ViewGroup container, int position) {
//        ReadDetailBean bean = mList.get(position);
//        View view = layoutInflater.inflate(R.layout.item_read_detail, container, false);
//        ImageView iv_pic = view.findViewById(R.id.iv_pic);
//        TextView tv_title = view.findViewById(R.id.tv_title);
//        ImageLoader.getInstance().displayImage(context, bean.getFilepath(), iv_pic);
//        tv_title.setText(bean.getTitle());
//        container.addView(view);
//        return view;
//    }

}
